﻿using MongoDB.Driver;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.ESG.Entities;
using Sustainalytics.Synchronization.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.CompanyKeyESGIssueLogic
{
    public class CompanyKeyESGIssueCommand : SyncEsgCommand<CompanyKeyESGIssue>
    {
        private readonly IMongoCollection<CompanyKeyESGIssue> companyKeyESGIssueCollection;

        public CompanyKeyESGIssueCommand(IMongoCollection<CompanyKeyESGIssue> companyKeyESGIssueCollection, ILogger logger) : base(logger)
        {
            this.companyKeyESGIssueCollection = companyKeyESGIssueCollection;
        }

        protected override async Task<DeleteResult> DeleteAssociatedRecordsAsync(IEnumerable<Guid> companiesIds, Guid? additionalDiscriminator = null)
        {
            return await companyKeyESGIssueCollection.DeleteManyAsync(cki => companiesIds.Contains(cki.Id)).ConfigureAwait(false);
        }

        protected override async Task InsertRecordsAsync(IEnumerable<CompanyKeyESGIssue> entities)
        {
            await companyKeyESGIssueCollection.InsertManyAsync(entities).ConfigureAwait(false);
        }
    }
}
